<div class="section-header">
  <h3 class="section-title"><%= t('application.guides') %></h3>
  <% if current_user == @user && current_user.confirmed?%>
  <%= link_to t('application.create_guide'), new_guide_path, class: "button right tiny create-guide-button" %>
  <% end %>
</div>

<div class="guides row guides-list">
  <div class="small-12 columns">
    <table>
      <% @user.guides.order_by([['created_at', :desc]]).each do |guide| %>
        <tr>
          <td>
            <%= render partial:'/guides/compatibility_circle', locals:{guide: guide} %>
            <%= link_to(guide.name, { :controller => 'guides', :action => 'show', :id => guide.id}, :class => 'action show guide-name') %>
            <% if guide.draft %>
               &nbsp<span class="label label-warning">Draft</span>
            <% end %>
          </td>
          <td>
            <%= link_to(guide.crop.name, { controller: 'crops',
              action: 'show',
              id: guide.crop.id }, :class => 'action show crop-name') %>
          </td>
          <td>
            <%= link_to(icon('fa', 'edit') + ' ' + t('application.edit'), { :controller => 'guides', :action => 'edit', :id => guide.id}, :class => 'action show', :title => t('users.show.guides.edit_title')) %>
          </td>
          <td>
            <%= link_to(icon('fa', 'trash') + ' ' + t('application.delete'), guide_path(guide), :method => 'delete', :class => 'action show', :title => t('users.show.guides.delete_title'), data: {confirm: "Are you sure?"}) %>
          </td>
        </tr>
      <% end %>
    </table>
    <% if @user.guides.count == 0 %>
      <div class="loading-content">
        <% if @user != current_user %>
          <%= t('.no_guides_yet') %>
        <% else %>
          <%= t('.you_have_not_created_a_guide') %>
        <% end %>
      </div>
    <% end %>
    <% if current_user == @user && current_user.favorited_guides.length > 0 %>
      <div>
        <h3 ng-show="showFavoritedGuides">Your Favorited Guides</h3>

        <a ng-click="showFavoritedGuides = !showFavoritedGuides"
          ng-hide="showFavoritedGuides">View your favorited guides <%= icon('fa', 'chevron-down') %></a>
        <a ng-click="showFavoritedGuides = !showFavoritedGuides"
          ng-show="showFavoritedGuides">Hide your favorited guides <%= icon('fa', 'chevron-up') %></a>
        <div ng-show="showFavoritedGuides">
          <table>
            <% @user.favorited_guides.order_by([['created_at', :desc]]).each do |guide| %>
              <tr>
                <td>
                  <%= render partial:'/guides/compatibility_circle', locals:{guide: guide} %>
                  <%= link_to(guide.name, { :controller => 'guides', :action => 'show', :id => guide.id}, :class => 'action show guide-name') %>
                </td>
                <td>
                  <%= link_to(guide.crop.name, { controller: 'crops',
                    action: 'show',
                    id: guide.crop.id }, :class => 'action show crop-name') %>
                </td>
              </tr>
            <% end %>
          </table>
        </div>
      </div>
    <% end %>
  </div>
</div>
